import {
  Column,
  CreateDateColumn,
  Entity,
  JoinTable,
  ManyToMany,
  OneToMany,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm';
import { Role } from './role.entity';
import { Favorite } from 'src/enterprise/entities/favorite.entity';
import { Post } from 'src/community/entities/post.entity';
import { Comment } from 'src/community/entities/comment.entity';
import { PostLike } from 'src/community/entities/postLikes.entity';
import { CommentLikes } from 'src/community/entities/commentLikes.entity';
import { UserLogin } from './user-login.entity';
import { Notification } from 'src/notification/entities/notification.entity';

@Entity({
  name: 'users',
})
export class User {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({
    length: 50,
    comment: '用户名',
  })
  username: string;

  @Column({
    length: 50,
    comment: '密码',
  })
  password: string;

  @Column({
    name: 'nick_name',
    length: 50,
    comment: '昵称',
  })
  nickName: string;

  @Column({
    comment: '邮箱',
    length: 50,
  })
  email: string;

  @Column({
    comment: '头像',
    length: 100,
    nullable: true,
  })
  headPic: string;

  @Column({
    comment: '手机号',
    length: 20,
    nullable: true,
  })
  phoneNumber: string;

  @Column({
    comment: '是否是管理员',
    default: false,
  })
  isAdmin: boolean;

  @CreateDateColumn({ type: 'datetime' })
  createTime: Date;

  @UpdateDateColumn({ type: 'datetime' })
  updateTime: Date;

  @ManyToMany(() => Role, (role) => role.users)
  @JoinTable({
    name: 'user_roles',
  })
  roles: Role[];

  @OneToMany(() => Favorite, (favorite) => favorite.user)
  favorites: Favorite[];

  @OneToMany(() => Post, (post) => post.user)
  posts: Post[];

  @OneToMany(() => Comment, (comment) => comment.user)
  comments: Comment[];

  @OneToMany(() => PostLike, (likes) => likes.user)
  postLikes: PostLike[];

  @OneToMany(() => CommentLikes, (likes) => likes.user)
  commentLikes: CommentLikes[];

  @OneToMany(() => UserLogin, (login) => login.user)
  logins: UserLogin[];

  @OneToMany(() => Notification, (notification) => notification.user)
  notifications: Notification[];
}
